package com.edu.demo.service.impl;


import com.edu.demo.entity.vo.QuartszSosVO;
import com.edu.demo.quartz.QuartzManager;
import com.edu.demo.service.IQuartzService;
import org.quartz.Job;
import org.springframework.stereotype.Service;

/**
 * 任务调度业务逻辑
 */
@Service
public class QuartzServiceImpl implements IQuartzService  {



    /**
     * 启动或停止业务 返回成功失败
     * @Author: Ashe1y
     * @param quartszSosVO
     * @return
     * boolean
     */
    @Override
    public boolean startOrStop(QuartszSosVO quartszSosVO) throws ClassNotFoundException {
        if(quartszSosVO.isStartOrStop()){
            QuartzManager.addJob(quartszSosVO.getJobName(),(Class<? extends Job>) Class.forName(quartszSosVO.getJobClass()),quartszSosVO.getCron());
        } else {
            QuartzManager.removeJob(quartszSosVO.getJobName());
        }
        return true;
    }
}
